# Contributor: Jakub Jirutka <jakub@jirutka.cz>
# Maintainer:
pkgname=ocaml-ppx_tools_versioned
_pkgname=ppx_tools_versioned
pkgver=5.2
pkgrel=1
pkgdesc="Tools for authors of ppx rewriters"
url="https://github.com/ocaml-ppx/ppx_tools_versioned"
arch="all !x86 !armhf !armv7 !s390x !mips !mips64"  # limited by ocaml aport
license="MIT"
depends="ocaml-runtime ocaml-migrate-parsetree"
makedepends="dune ocaml ocaml-compiler-libs ocaml-findlib
	ocaml-migrate-parsetree-dev opam"
# textrels needed for ppc64le
# no tests provided
options="textrels !check"
subpackages="$pkgname-dev"
source="$pkgname-$pkgver.tar.gz::https://github.com/ocaml-ppx/$_pkgname/archive/$pkgver.tar.gz"
builddir="$srcdir/$_pkgname-$pkgver"

build() {
	cd "$builddir"
	jbuilder build @install
}

package() {
	cd "$builddir"

	mkdir -p "$pkgdir"/usr/lib/ocaml
	jbuilder install \
		--destdir="$pkgdir"/usr \
		--libdir="$pkgdir"/usr/lib/ocaml

	# There's just a readme and changelog.
	rm -Rf "$pkgdir"/usr/doc

	# Remove annotation files and sources.
	cd "$pkgdir"/usr/lib/ocaml/$_pkgname
	rm -f *.cmt* */*.cmt* *.ml */*.ml
}

dev() {
	default_dev
	depends="$pkgname=$pkgver-r$pkgrel"

	cd "$pkgdir"

	local path; for path in $(find usr/lib/ocaml/$_pkgname \
		-name '*.cmx' \
		-o -name '*.cmxa' \
		-o -name '*.mli')
	do
		mkdir -p "${path%/*}"
		mv "$path" "$subpkgdir"/${path%/*}/
	done
}

sha512sums="1efb7fc24f0b909d948aca53abee6e0613aaf101e6cf914772557ec00c879890d50b9c6e232f55a54381eab164a40d796d953b4992ef40a6e9141abd2b409cba  ocaml-ppx_tools_versioned-5.2.tar.gz"
